package com.hsylient.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;
import java.io.IOException;

@WebFilter(
        filterName = "loginFilter",
        urlPatterns = "/*",
        initParams = {
                @WebInitParam(name = "charset", value = "UTF-8")
        }
)
public class LoginFilter implements Filter {

    private String charset;

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        charset = filterConfig.getInitParameter("charset");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        request.setCharacterEncoding(charset);
        response.setCharacterEncoding(charset);
    }

    @Override
    public void destroy() {
        Filter.super.destroy();
    }
}
